﻿MPT.addAction("friend_invite", function(_elm) {

    var copy_jQ = $('.e_copy', _elm);
    var dialog_jQ = $('.e_dialog', _elm);
    var input_jQ = $('.e_input', _elm);

    var progress_id;

    var initialize = function() {

        Tab.switchFriend();
        var copy_text = input_jQ.val();

        if (window.clipboardData) {  //IE浏览器，剪切板实现
            copy_jQ.click(function() {
                window.clipboardData.setData('text', copy_text);
                if (progress_id) clearTimeout(progress_id);
                dialog_jQ.show();
                progress_id = setTimeout("$('.e_dialog').hide();", 5000);
            });
        } else {    //其他浏览器，ZC实现
            $.getScript(MPT.Config.sta_js_lib_http + '/clipboard/ZeroClipboard.js', function() {

                ZeroClipboard.setMoviePath(MPT.Config.sta_js_lib_http + '/clipboard/ZeroClipboard.swf');
                var clip = new ZeroClipboard.Client();
                clip.setHandCursor(true);
                clip.setText(copy_text);
                clip.glue("copy");
                clip.addEventListener("complete", function(client) {
                    if (progress_id) clearTimeout(progress_id);
                    dialog_jQ.show();
                    progress_id = setTimeout("$('.e_dialog').hide();", 5000);
                });

                $(window).resize(function() {
                    clip.reposition();
                });

                var removeFlash = function() {
                    $('#ZeroClipboardMovie_1').parent().remove();
                };

                if (window.addEventListener) {
                    //其它浏览器的事件代码: Mozilla, Netscape, Firefox
                    window.addEventListener('hashchange', removeFlash, false);
                }
                else {
                    //IE 的事件代码 
                    window.attachEvent('onhashchange', removeFlash);
                }
            });
        }
    };

    initialize();

});

